package com.notknow.product.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.notknow.product.dto.UserInfoDto;
import com.notknow.product.service.UserInfoService;

@RestController
@RequestMapping("/userInfo")
public class UserInfoController {
	
	@Autowired
	private UserInfoService userInfoService;
	
	/**
	 * 登录
	 * @return ResponseEntity 
	 */
	@RequestMapping(value="/login",method={RequestMethod.GET})
	@ResponseBody
	public ResponseEntity<String> login(@RequestBody UserInfoDto userInfoDto) {
		return new ResponseEntity<String>(JSONObject.toJSONString(userInfoService.findUserInfoByUsernamePasswory(userInfoDto)),HttpStatus.OK);
	}
	
	/**
	 * 添加用户
	 * @return ResponseEntity 
	 */
	@RequestMapping(value="/addUserInfo",method={RequestMethod.POST})
	@ResponseBody
	public ResponseEntity<String> addUserInfo(@RequestBody UserInfoDto userInfoDto) {
		userInfoService.addUserInfo(userInfoDto);
		return new ResponseEntity<String>(HttpStatus.OK);
	}
	
//	/**
//	 * 删除用户
//	 * @return ResponseEntity 
//	 */
//	@RequestMapping(value="/addUserInfo",method={RequestMethod.POST})
//	@ResponseBody
//	public ResponseEntity<String> addUserInfo(@RequestBody UserInfoDto userInfoDto) {
//		userInfoService.addUserInfo(userInfoDto);
//		return new ResponseEntity<String>(HttpStatus.OK);
//	}
	
}
